Skip to content

fix(p2p/discover): avoid dropping unverified nodes when table is almost empty #21396 #21554#2434

Open
gzliudan wants to merge 2 commits into
XinFinOrg:dev-upgradefrom
gzliudan:p2p-discover-small-net-2
Open

fix(p2p/discover): avoid dropping unverified nodes when table is almost empty #21396 #21554#2434
gzliudan wants to merge 2 commits into
XinFinOrg:dev-upgradefrom
gzliudan:p2p-discover-small-net-2

Conversation

@gzliudan

@gzliudan gzliudan commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

Ref:

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7c9ee20e-63cd-4ef4-bb4c-ee9af3a5903c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gzliudan gzliudan force-pushed the p2p-discover-small-net-2 branch from a7d1594 to 81fa248 Compare July 3, 2026 03:50
@gzliudan gzliudan changed the title fix(p2p/discover): avoid dropping unverified nodes when table is almost empty #21396 fix(p2p/discover): avoid dropping unverified nodes when table is almost empty #21396 #21554 Jul 3, 2026
@gzliudan gzliudan force-pushed the p2p-discover-small-net-2 branch from 81fa248 to 3aa7566 Compare July 3, 2026 04:41
@gzliudan gzliudan requested a review from Copilot July 3, 2026 08:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Discovery v4 UDP handling by extracting the wire-level packet codec/types into a dedicated p2p/discover/v4wire package and adjusts lookup/findnode behavior to avoid prematurely dropping (unverified) nodes when the routing table is sparse.

Changes:

  • Introduces p2p/discover/v4wire (packet types + encode/decode + EIP-8 vectors) and updates UDPv4 to use it.
  • Updates FINDNODE/NEIGHBORS handling: avoid surfacing unverified nodes when verified ones exist, but still return unverified when the table has no verified nodes; also avoids returning a timeout if at least one NEIGHBORS reply arrived.
  • Adjusts lookup failure-drop behavior to only drop a node after repeated failures when its bucket isn’t close to empty; adds/updates tests (including small-net convergence).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
p2p/discover/v4wire/v4wire.go Adds Discovery v4 wire packet types and codec (encode/decode, pubkey helpers, constants).
p2p/discover/v4wire/v4wire_test.go Adds EIP-8 forward-compatibility decoding vectors for the new wire package.
p2p/discover/v4_udp.go Switches UDPv4 to v4wire packets/codec and updates FINDNODE/NEIGHBORS handling and matcher behavior.
p2p/discover/v4_udp_test.go Updates UDPv4 tests for v4wire and adds a small localhost network convergence test.
p2p/discover/v4_lookup_test.go Updates lookup tests to use v4wire packet types.
p2p/discover/table.go Replaces closest with findnodeByID (prefer-live semantics) and adds bucketLen.
p2p/discover/table_test.go Updates table tests to cover findnodeByID.
p2p/discover/node.go Removes now-relocated node key recovery helper.
p2p/discover/lookup.go Avoids dropping nodes on repeated empty FINDNODE results when their bucket is too small.

Comment thread p2p/discover/table.go Outdated
Comment thread p2p/discover/v4wire/v4wire.go
fjl and others added 2 commits July 3, 2026 16:33
…thereum#21147

This moves all v4 protocol definitions to a new package, p2p/discover/v4wire.
The new package will be used for low-level protocol tests.
…st empty ethereum#21396 ethereum#21554

This change improves discovery behavior in small networks. Very small
networks would often fail to bootstrap because all member nodes were
dropping table content due to findnode failure. The check is now changed
to avoid dropping nodes on findnode failure when their bucket is almost
empty. It also relaxes the liveness check requirement for FINDNODE/v4
response nodes, returning unverified nodes as results when there aren't
any verified nodes yet.

The "findnode failed" log now reports whether the node was dropped
instead of the number of results. The value of the "results" was
always zero by definition.

Co-authored-by: Felix Lange <fjl@twurst.com>
@gzliudan gzliudan force-pushed the p2p-discover-small-net-2 branch from 3aa7566 to a6ba7ee Compare July 3, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants